import json
from flask import Response, make_response
from bson import json_util


def to_json(object):
    json_str = ''
    # if (type(object).__name__ == 'dict'):
    if isinstance(object, (list, dict)):
        json_str = json.dumps(
            object, default=lambda o: o.__dict__, sort_keys=True, indent=4)
        pass
    else:
        json_str = json.dump(
            object, default=lambda o: o.__dict__, sort_keys=True, indent=4)
    return json_str


def get_name():
    import random
    xing = '赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜'
    ming = '伟勇军磊涛斌强鹏杰峰超波辉刚健明亮俊飞凯浩华平鑫毅林洋宇敏宁建兵旭雷锋彬龙翔阳剑东博威海巍晨炜帅岩江松文云力成琦进昊宏欣坤冰锐震楠佳忠庆杨新骏君栋青帆静荣立虎哲晖玮瑞光钢丹坚振晓祥良春晶猛星政智琪永迪冬琳胜康彪乐诚志维卫睿捷群森洪扬科奇铭航利鸣恒源聪凡颖欢昕武雄洁川清义滨皓达民跃越兴正靖曦璐挺淼泉程韬冲硕远昆瑜晔煜红权征雨野慧萌山丰珂彤悦朋钧彦然枫嘉峥寅烨铮卓畅钊金可昱爽盛路晋谦克方闯耀奎一晟勤豪安尧全琛腾队鸿玉泽凌渊蕾广顺莹英峻攀宾驰燕霖喆椒国恺潇琨轶芳吉亚梁焱侃臻嵩岳炯艳宝岗斐啸元辰萍柯羽培通天麟晗菲雪铁贺钰戈灿琼锦生原洲炎丽勋奕艺中德轩京标旺南黎禹莉蔚总益祺骥沛汉真非鹤升蒙城钦锴骁壮罡键瑶虹石展翼为灏玲放娜露赞娟倩懿劲婷策魁霄冉敬卿均治迅臣桦镇骞河希瑾鹰舟丁涵弘纲泳理福俭乾纯双屹涌根怡果田岭昭飚勃嵘熙贤申琰宽鼎滔昌璞逸贵喜昂柳韶瑛伦茂景柱岚实珏霞园学惠衡风玺赫桐寒圣陈旋礼霆月侠密堃富薇仁浪津垒齐炼瀚泓灵朝夏严意银璇鲲易行品垄靓苏澄赛思旗淳雯继友和革延能菁叶隽烽昶笑裕鲁铎昀骅高翀润熠锟望卡微拓名秋冶雁开定想舒庚蓉牧重孟澎信郁珉钟盼恩周潮季烈魏奔承玎来桥尚增婧茜前琴麒竞童舜会柏冠佩游珊融满添咏响珩杉韧梅乔同梦树杭念遥苗胤榕耿崇湘里疆旻启烁楷才仲隆媛晴章舰璟桔李影亭珺言笛弛营宪渝发逊运豹翊研登炳蕊鉴妍焰颂闻桢镭特曙盟贝千保功竹印玥夭冀阔圆湛澍争众肖祯默珍煌余准忱宸普韦舸创芸彭泰心廷其业水焕炬韵裙干唯轲陆陶将骋战歆朔耕崴操幸向葵潜凤兰仪沙胡璋秦珑朗举列蓓纬垚歌献或见多谊迎州声婕栩男衍洵犇颢照辛有育甲禄起淮弋坦量楚熹劫勉典诺溪显毓稳甫羿端旦焘辑宣宙岑存迁万煦渤沁甜日翰淦劼庭徽豫锬铸蚵也好颉雍怀北西耘秀肠玄令蓬联斯霁朕箭坡澜馨瀛港岱宗闽励飙琥谷异嵬垣年尉习格锨桑讳丛淞领深赢宜律朴龚卉化陵庄财墨直煊欧棋孝子弢冕傲劭丞如燃铖畏崧汀弦墩溢崎容锁韩曼汽地芬上佶连郑兆纪盾相翌盈慰戟植晏任农'
    X = "".join(random.choice(xing) for i in range(1))
    M = "".join(random.choice(ming) for i in range(2))
    return X+M


def response(result):
    if not result is None:
        if isinstance(result, str):
            return result
        else:
            return Response(json_util.dumps(result), mimetype='application/json')
    return Response(None, mimetype='application/json')
